Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix paddleOCR size issue #775

Merged
merged 1 commit into from
Mar 26, 2021
Merged

Conversation

lanking520
Copy link
Contributor

Description

The word recognition OCR model from PaddlePaddle require height to be fixed 32 or an error will be thrown.

return new int[] {h32 * 32, w32 * 32};
int w32 = Math.max((int) w / 32 / h32, 1);
// height must be 32 (fixed)
return new int[] {32, w32 * 32};
Copy link
Contributor

@stu1130 stu1130 Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if height is fixed to 32, shouldn't the algorithm be just w = 32 / h * w ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to make sure width are base 32 number and has proper aspect ratio

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work:

int ratio = Math.floorDiv(w, h);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this doesn't apply here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

floorDiv cannot be used on floating number

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Jake pointed out, if you height is always 32, the width should simply be 32 * ratio,
no need to test if size is less then 32 or not. the whole function can be:

int ratio =  Math.max((int) w / h, 1);
return new int[] {32, 32 * ratio};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this way, the last inference result is always wrong. Will try this implementAction again.

int w32 = (int) w / 32;
return new int[] {h32 * 32, w32 * 32};
private int[] resize32(double w) {
int width = ((int) Math.max(32, w)) / 32 * 32;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. This basically keep the original width and removed the remainder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it trimmed the width to a 32 based number. The apect ratio didn't help on the inference result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird, Can you add a comments here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@lanking520 lanking520 merged commit 7f66ab1 into deepjavalibrary:master Mar 26, 2021
stu1130 pushed a commit that referenced this pull request Mar 26, 2021
@lanking520 lanking520 deleted the boolean branch May 6, 2021 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants